<?php
/**
 * 
 * Model to handle companies
 *
 * @category Abovo
 * 
 * @package Abovo_Model
 * 
 * @author Antti Holvikari <anttih@gmail.com>
 * 
 * @license http://opensource.org/licenses/bsd-license.php BSD
 * 
 */

/**
 * 
 * Model to handle companies
 *
 * @category Abovo
 * 
 * @package Abovo_Model
 * 
 */
class Abovo_Model_Tags extends Abovo_Sql_Table {
    
    /**
     * 
     * Fetches id for tag name
     * 
     * @param string $tag Tag name
     * 
     * @return int|bool Tags id or boolean false if tag not found
     * 
     */
    public function fetchId($tag)
    {
        $sel = Solar::factory('Solar_Sql_Select');
        
        $id = $sel->from($this->_name, 'id')
                  ->where('name = ?', $tag)
                  ->fetch('value');
        
        return $id;
    }
    
    /**
     * 
     * Table set up
     * 
     * @return void
     * 
     */
    protected function _setup()
    {
        $this->_name = 'tags';
        
        $this->_col['name'] = array(
            'type'    => 'varchar',
            'size'    => 100,
            'require' => true,
        );
        
        // Make sure sql is available
        if (! Solar::isRegistered('sql')) {
            Solar::register('sql', Solar::factory('Solar_Sql'));
        }
    }
}
